< previous page page_292 next page >

Page 292
0292-01.gif
Figure T2-1:
64K of memory on an 8-bit system
checking and setting individual bits will be covered in Tutorial 3, ''A Bool and Its Bitfields Are Soon Parted."
On an 8-bit system, memory is accessed by bytes. Every byte in memory has a unique address that corresponds to its location. Thus the address of the first byte of memory is 0, the second is 1, and so on until the end of memory.
Figure T2-2 shows a 32-bit system with 4.2GB of memory. Why 4.2 GB? Because with 32 bits, you can have 4.2 trillion possible values. If those values are memory addresses, you can access up to 4.2 trillion bytes. This is also referred to as a 32-bit address space. Note that the memory is organized a bit differently. Each location in memory is 32 bits wide, yet the address increases by four for each location. What does this mean? It means that the processor reads and writes memory in 32-bit blocksfour bytes at a time. But it is still capable of accessing individual bytes. Why is this important?
If a processor can move data four bytes at a time, it can move data at least four times faster than a processor that can only move data one byte at a time. It's actually even faster than that, because not only are you moving larger blocks of data, you also save all of the extra instructions needed to access the individual bytes. This is one of the main reasons that 32-bit processors are faster than 8-bit processors. What happens if you want to access a 32-bit long variable that is located at address &H100? No problemthe processor goes directly to that address and reads the data in one operation. But what if that long variable is located at address &H101? If you're running an Intel CPU, the processor actually has to perform two separate read operations. Three bytes of the variable can be found at location &H100, but one must be retrieved from location &H104. The CPU must then reassemble the data into a single long variable within the CPU in order to perform operations on the data! This is a time-consuming operation, to say the least. On some processors, the situation is even worsethe processor simply raises an invalid operation fault! This leads to a type of problem called an "alignment problem," which will be discussed in Tutorial 7, "Classes, Structures, and User-Defined Types."

 
< previous page page_292 next page >